import {action, observable} from "mobx";
import {getBlog} from "../api/BlogApi";

class store {
    @observable blogList = [];
    @observable total;
    @observable keyword = "";
    @observable number = 1;
    @observable size = 5;
    @observable cardWidth = 5;


    @action  update = async (key, pageNum, pageSize) => {
        if (key !== undefined) {
            this.keyword = key;
        }

        if (pageNum !== undefined) {
            this.number = pageNum;
        }

        if (pageSize !== undefined) {
            this.size = pageSize;
        }

        const request = await getBlog(this.keyword, this.number, this.size);
        const data = request.data;
        console.log(data)
        let blogList = data.list;
        this.blogList = blogList;
        this.total = data.total;
    }

    @action updateCardWidth = (number) => {
        console.log(`更新数据${number}`)
        this.cardWidth = number;
    }
}

const x = new store();
export default x;